home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / dev / gui / gui4cli.lha / Gui4Cli / G4C / CED / cedbar.gc < prev    next >
Encoding:
Gui4CLI script  |  1999-12-02  |  15.8 KB  |  619 lines

  1. G4C
  2.  
  3. ; $VER: CedBar.gc 3.5 ( by dck - 20.8.98 )
  4. ; ----------------------------------------------------------------------
  5. ; A GUI providing a toolbar for the CygnusEd text editor.
  6. ; This is a work in perpetual progress, as I use it myself..
  7. ; CygnusEd is a commercial product from ASDG Inc. (AFAIK)
  8.  
  9. ; What we do is define various icons, which we use as if they 
  10. ; were buttons and send the appropriate rexx command to $cedport, 
  11. ; which contains the name of the current CEd's arexx port.
  12.  
  13. ; According to your monitor/resolution/font etc the Icon-buttons may 
  14. ; seem too small or too big - just redesign them to your liking.
  15.  
  16. ; =======================================================================
  17.  
  18. WINBIG -1 0 625 14 "" ; note : no title - since don't want borders
  19. WinType 000010
  20. ; winbackground pattern 3 2 ; try it..
  21. varpath 'cedbar.g/cedmark.g'
  22. UseTopaz        ; because it's a non-resizable window
  23.  
  24. ; -----------------------------------------------------------
  25. ;       on loading
  26. ; -----------------------------------------------------------
  27.  
  28. xOnLoad                       ; On Loading set the default values...
  29.  
  30.     cedname = CEd     ; << **** PUT HERE THE FULL PATH OF CED ********
  31.  
  32.     cedClip = 0
  33.     cedMark = 1
  34.     cedSend = ""
  35.     cedFile = ""
  36.     newflag = 0
  37.     Update cedbar.gc 1 $cedClip
  38.     setgad cedbar.gc 20 HIDE   ; hide listview
  39.     setgad cedbar.gc 11/12 HIDE   ; hide amiga guide & launch mode icons
  40.     barmode = NORMAL     ; or GUIDE - can add more..
  41.     GuiClose cedbar.g       ; Close the small window (if it was open)
  42.  
  43.     gosub cedbar.gc StartUpCed      ; See which ced is calling us
  44.     if $$sys.fsn[0][6] != 'Cygnus'  ; if we are called from an other screen
  45.        cedscreen = CygnusEdScreen   ; get the 1st ced's screen name
  46.        instance = $cedport[-1][1]
  47.        if $instance > 0
  48.        and $instance <= 9
  49.            appvar cedscreen $($instance + 1) 
  50.        else
  51.            appvar cedscreen 1 
  52.        endif
  53.  
  54.         setscreen #this $cedscreen
  55.         guiopen cedbar.gc
  56.         guiscreen #this front
  57.         setscreen #this '*'
  58.  
  59.     else
  60.         GuiOpen  cedbar.gc
  61.     endif
  62.  
  63.     GuiLoad :cedbar.g    ; the small bar
  64.     GuiLoad :cedMark.g      ; the Mark Set/Go window
  65.     GuiLoad :cedclip.g      ; clipboard viewer
  66.     guiload :filereq.gc        ; the file requester
  67.  
  68.     ; see under which ced we're running..
  69.     info gui cedbar.gc
  70.     cedscreen = $$win.screen
  71.     cedport = rexx_ced
  72.     if $cedscreen[0][6] == 'Cygnus'   ; make sure it's a ced pubscreen
  73.        instance = $cedscreen[-1][1]   ; get last letter
  74.        if $instance > 1
  75.        and $instance <= 9        ; adjust port name (if needed)
  76.            appvar cedport $($instance - 1) 
  77.        endif
  78.     endif
  79.  
  80.     ; find & load the Gui4Cli extension which provides us with 
  81.     ; extra commands we can use with the CALL command
  82.     ifexists port LVFormat
  83.        call LVFormat Register         ; notify it that we want it too
  84.     else
  85.        ; look in our dir..
  86.        extract cedbar.gc guipath mypath
  87.        joinfile $mypath lvformat progname
  88.        joinfile $progname lvformat progname
  89.        ifexists file $progname
  90.           run $progname
  91.        elseifexists file guis:ext/lvformat/lvformat
  92.           run guis:ext/lvformat/lvformat
  93.        else  ; look for it in our path..
  94.            progname = lvformat
  95.            extract progname fullpath progname
  96.            if $progname > ''
  97.                run '$progname'
  98.             else
  99.               ezreq 'Could not find LVFormat!' OK ''
  100.             endif
  101.        endif
  102.     endif
  103.  
  104. ; -----------------------------------------------------------
  105. ;       ending events
  106. ; -----------------------------------------------------------
  107.  
  108. xONQuit
  109.     GuiQuit cedbar.g        ; unload all the other GUIs
  110.     GuiQuit cedmark.g
  111.     guiquit cedclip.g
  112.     guiquit addlink.g
  113.     guiquit addeffect.g
  114.     guiquit addnode.g
  115.     guiquit indent.g
  116.     guiquit GuideEd.g
  117.     guiquit wrap.g
  118.     guiquit filereq.gc
  119.     ifexists port LVFormat  ; quit out handler
  120.        call LVFormat quit
  121.     endif
  122.     ifexists file t:tempnode
  123.        delete t:tempnode
  124.     endif
  125.  
  126. xOnFail
  127.    guiwindow cedbar.gc resume
  128.  
  129. ; -----------------------------------------------------------
  130. ;       Routine - Find ced
  131. ; -----------------------------------------------------------
  132.  
  133. xRoutine StartUpCed
  134.     local count
  135.     count = 1
  136.  
  137.     portname = rexx_ced
  138.  
  139.     ; look for any instance of ced
  140.     ifexists port ~rexx_ced
  141.        while $count < 10
  142.           IfExists PORT 'rexx_ced$count'
  143.              portname = 'rexx_ced$count'
  144.              return
  145.           endif
  146.           ++count
  147.        endwhile
  148.     else
  149.        return
  150.     endif
  151.  
  152.     run '$cedname'    ; not found - start it up
  153.     Wait PORT rexx_ced 30   ; wait for ced to load
  154.     if $$RETCODE > 0
  155.        ezreq "CygnusEd was not found!" EXIT ""
  156.        GuiQuit cedbar.gc
  157.        Stop
  158.     endif
  159.     Wait SCREEN CygnusEdScreen1 30     ; if Screen does not open, use WB
  160.     portname = rexx_ced
  161.  
  162. ; -----------------------------------------------------------
  163. ;       window handling events
  164. ; -----------------------------------------------------------
  165.  
  166. xOnRMB              ; rotate the last 8 buttons
  167.     ; GuiClose cedbar.gc
  168.     ; GuiOpen cedbar.g
  169.     gosub cedbar.gc guichange
  170.  
  171. XICON 2 0 :icons/wnClose   ; the Q icon
  172.     ezreq "Last chance..\nQuit ?" YES|CANCEL choice
  173.     if $choice = 1
  174.        GuiQuit cedbar.gc
  175.     endif
  176.  
  177. XICON 15 1 :icons/right    ; the > icon togle big/small windows
  178.     GuiClose cedbar.gc
  179.     GuiOpen cedbar.g
  180.  
  181. ; -----------------------------------------------------------
  182. ;       New file
  183. ; -----------------------------------------------------------
  184.  
  185. XICON 30 0 :icons/New
  186.     SendRexx $cedport "open new"
  187.  
  188. ; -----------------------------------------------------------
  189. ;       Open file
  190. ; -----------------------------------------------------------
  191. ; ----- use "filereq.gc" (if it exists in our dir - else ASL)
  192.  
  193. XICON 55 0 :icons/Open
  194.     newflag = 1     ; set flag to know that we pressed the open button
  195.     extract cedbar.gc guipath frqpath
  196.     joinfile $frqpath filereq.gc frq
  197.     joinfile $frqpath CedFav fav
  198.     ifexists file $frq
  199.         ; get the current filename so we can get it's path
  200.         sendrexx $cedport 'status filename'
  201.         filename = $$rexxret
  202.         extract filename path path
  203.         ; load & open fireq.gc
  204.         extract frq unquote frq
  205.         guiload $frq cedbar.gc LoadFile $cedbar.gc/path $fav
  206.     else
  207.         ; if no filereq.gc open normally
  208.         SendRexx $cedport "open"
  209.     endif
  210.  
  211. ; ----- the routine that will be called from filereq.gc for *every*
  212. ;       file chosen in it's listview
  213.  
  214. xroutine LoadFile filename
  215.     ; if there have been changes made or it's an existing file - open a new file
  216.     sendrexx $cedport 'status numchanges'
  217.     changes = $$rexxret
  218.     if $newflag = 0
  219.     or $changes > 0
  220.        SendRexx $cedport "open new"
  221.     endif
  222.     newflag = 0   ; set flag = all next files (multiselected) => open new view
  223.     SendRexx $cedport 'open $filename'
  224.  
  225. ; ------ add current path to the filename - store it in cedbar.gc/fn
  226.  
  227. xroutine makefile fn
  228.     local pth
  229.     extract cedbar.gc guipath pth
  230.     joinfile $pth $fn fn
  231.  
  232.  
  233. ; -----------------------------------------------------------
  234. ;       View handling icons
  235. ; -----------------------------------------------------------
  236.  
  237. XICON 80 0 :icons/Big
  238.     SendRexx $cedport "expand view"
  239.  
  240. ; -----------------------------------------------------------
  241. ;       Save as.., Save
  242. ; -----------------------------------------------------------
  243.  
  244. XICON 95 0 :icons/saveas
  245.     SendRexx $cedport "save as"
  246.  
  247. XICON 120 0 :icons/save
  248.     SendRexx $cedport "save"
  249.  
  250. ; -----------------------------------------------------------
  251. ;       Quit
  252. ; -----------------------------------------------------------
  253.  
  254. XICON 145 0 :icons/quit
  255.     ; get information
  256.     sendrexx $cedport 'status numchanges'
  257.     changes = $$rexxret
  258.     sendrexx $cedport 'status filename'
  259.     filename = $$rexxret
  260.     sendrexx $cedport 'status totalnumviews'
  261.     views = $$rexxret
  262.     if $changes > 0
  263.        ezreq '$changes changes have been made.\nQuit $filename ?\n' 'Quit|Save & Quit|CANCEL' choice
  264.        if $choice = 0
  265.           stop
  266.        elseif $choice = 2
  267.           SendRexx $cedport "save"
  268.           ; we will quit later..
  269.        endif
  270.     endif
  271.     if $views = 1   ; this is the last file - jump to next ced, if any..
  272.         sendrexx $cedport 'activate next ced'    
  273.         if $$rexxret > 0
  274.             oldcedport = $cedport
  275.            cedport = $$rexxret ; the new port name
  276.             guiclose cedbar.gc
  277.            SendRexx $oldcedport "quit"
  278.            SendRexx $cedport "status pubscreenname"
  279.            cedscreen = $$rexxret
  280.             guiopen cedbar.gc
  281.             stop
  282.         else    ; - give him one more chance..
  283.            ezreq 'Really quit ?' "Quit!|CANCEL" choice
  284.            if $choice = 0
  285.               stop
  286.            endif
  287.            ; the guy just won't listen to reason..
  288.            guiclose cedbar.gc   ; close window so ced can quit
  289.            guiclose cedmark.g
  290.            guiquit cedbar.gc    ; and quit.. (after all commands have executed)
  291.         endif
  292.     endif
  293.     SendRexx $cedport "quit"
  294.  
  295. ; -----------------------------------------------------------
  296. ;       Cut & Paste
  297. ; -----------------------------------------------------------
  298.  
  299. XICON 170 0 :icons/cut
  300.     SendRexx $cedport cut
  301.     lvuse CedClip.g 1
  302.     lvchange 'CLIPS:$cedClip'
  303.  
  304. XICON 195 0 :icons/copy
  305.     SendRexx $cedport copy
  306.     lvuse CedClip.g 1
  307.     lvchange 'CLIPS:$cedClip'
  308.  
  309. XICON 220 0 :icons/paste
  310.     SendRexx $cedport paste
  311.     lvuse CedClip.g 1
  312.     lvchange 'CLIPS:$cedClip'
  313.  
  314. ; -----------------------------------------------------------
  315. ;       Change the clipboard unit (use cedclip.g)
  316. ; -----------------------------------------------------------
  317.  
  318. XAREA 246 0 40 14 box   ; use an area gad to get button click over
  319.     guiopen cedclip.g    ; the text gad below..
  320.     
  321. TEXT 246 1 40 12 "" 10 box    ; the number of the clipboard unit
  322.     GadID 1
  323.  
  324. XICON 287 1 :icons/Up  ; the up/down icons
  325.     ++cedClip
  326.     gosub cedclip.g changeunit
  327.  
  328. XICON 287 7 :icons/Down
  329.     --cedClip
  330.     gosub cedclip.g changeunit
  331.  
  332. ; -----------------------------------------------------------
  333. ;       Undo/Redo, Find & Replace
  334. ; -----------------------------------------------------------
  335.  
  336. XICON 300 0 :icons/undo
  337.     SendRexx $cedport "undo"
  338.  
  339. XICON 315 0 :icons/redo
  340.     SendRexx $cedport "redo"
  341.  
  342. XICON 330 0 :icons/find
  343.     SendRexx $cedport "search for"
  344.  
  345. XICON 356 1 :icons/right
  346.     SendRexx $cedport "repeat search forwards"
  347.  
  348. XICON 370 0 :icons/replace
  349.     SendRexx $cedport "replace"
  350.  
  351. XICON 396 1 :icons/right
  352.     SendRexx $cedport "repeat replace"
  353.  
  354.  
  355. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  356. ;       change gui..
  357. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  358.  
  359. XICON 410 0 :icons/change
  360.     gosub cedbar.gc guichange
  361.  
  362. xroutine guichange    ; also called from xOnRMB
  363.     if $barmode = NORMAL
  364.        barmode = ALT1
  365.        setgad cedbar.gc 10 HIDE
  366.        setgad cedbar.gc 11 SHOW
  367.        setgad cedbar.gc 12 HIDE
  368.     elseif $barmode = ALT1
  369.         barmode = ALT2
  370.        setgad cedbar.gc 10 HIDE
  371.        setgad cedbar.gc 11 HIDE
  372.        setgad cedbar.gc 12 SHOW
  373.     else ; ALT2 mode
  374.        barmode = NORMAL
  375.        setgad cedbar.gc 10 SHOW
  376.        setgad cedbar.gc 11 HIDE
  377.        setgad cedbar.gc 12 HIDE
  378.     endif
  379.     partredraw cedbar.gc 430 0 625 14
  380.  
  381.  
  382. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  383. ;    gadid 10
  384. ; ===========================================================
  385. ;    NORMAL mode
  386. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  387.  
  388. xICON 425 0 :icons/all
  389.     gadid 10
  390.     SendRexx $cedport "beg of file"
  391.     SendRexx $cedport "mark"
  392.     SendRexx $cedport "end of file"
  393.  
  394. xICON 450 0 :icons/goto
  395.     gadid 10
  396.     GuiOpen cedmark.g
  397.  
  398. xICON 475 0 :icons/clear
  399.     gadid 10
  400.     SendRexx $cedport "clear"
  401.  
  402. xICON 500 0 :icons/colmark
  403.     gadid 10
  404.     SendRexx $cedport "mark columnar"
  405.  
  406. xICON 525 0 :icons/brackets
  407.     gadid 10
  408.     SendRexx $cedport "find matching bracket"
  409.  
  410. xICON 550 0 :icons/print
  411.     gadid 10
  412.     SendRexx $cedport "print file"
  413.  
  414. xICON 575 0 :icons/nextjump            ; jump to next ced with file
  415.     gadid 10
  416.     local newced
  417.     newced = ''
  418.     gosub #this getname
  419.     sendrexx $cedport 'status numchanges'
  420.     changes = $$rexxret
  421.     if $changes > 0 ; if there were changes, save file..
  422.         sendrexx $cedport 'save'
  423.     endif
  424.     guiclose cedbar.gc
  425.     SendRexx $cedport "activate next ced"
  426.     if $$rexxret <= "0"     ;  if there is no next ced, create one..
  427.         oldcedport = $cedport
  428.         SendRexx $cedport "spawn new ced"
  429.         if $$rexxret = 1
  430.             cedport = 0
  431.             while $cedport <= "0"    ; wait for ced port
  432.                 delay 5
  433.                 SendRexx $oldcedport "activate next ced"
  434.                 cedport = $$rexxret
  435.             endwhile
  436.             newced = NEW        ; mark new (see down)
  437.         else                         ; failed to launch new ced
  438.             flash        
  439.             stop
  440.         endif
  441.     else
  442.         oldcedport = $cedport
  443.        cedport = $$rexxret ; the new port name
  444.     endif   
  445.    SendRexx $oldcedport "quit" ; close the file after closing cedbar
  446.    SendRexx $cedport "status pubscreenname"
  447.    cedscreen = $$rexxret
  448.    if $newced != NEW
  449.         SendRexx $cedport "open new"
  450.     endif
  451.     SendRexx $cedport "open $filename"
  452.     SendRexx $cedport "expand view"
  453.     guiopen cedbar.gc
  454.  
  455. xICON 600 0 :icons/nextced                ; jump to next ced - no file
  456.     gadid 10
  457.     guiclose cedbar.gc
  458.     SendRexx $cedport "activate next ced"
  459.     if $$rexxret > "0"     ;  if there is a next ced
  460.        cedport = $$rexxret ; the new port name
  461.        SendRexx $cedport "status pubscreenname"
  462.        cedscreen = $$rexxret
  463.     endif
  464.     guiopen cedbar.gc
  465.  
  466.  
  467. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  468. ;    gadid 11
  469. ; ===========================================================
  470. ;    ALT1 mode
  471. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  472.  
  473. xICON 425 0 :icons/indent
  474.     gadid 11
  475.     guiload :indent.g
  476.  
  477. xICON 450 0 :icons/unindent
  478.     gadid 11
  479.     SendRexx $cedport cut
  480.     lvuse CedClip.g 1
  481.     lvchange 'CLIPS:$cedClip'
  482.     call LVFormat UnIndent
  483.     lvsave 'CLIPS:$cedClip'
  484.     SendRexx $cedport paste
  485.  
  486. xICON 475 0 :icons/wrap
  487.     gadid 11
  488.     guiload :wrap.g
  489.  
  490. xICON 500 0 :icons/empty
  491.     gadid 11
  492.  
  493. xICON 525 0 :icons/empty
  494.     gadid 11
  495.  
  496. xICON 550 0 :icons/empty
  497.     gadid 11
  498.  
  499. xICON 575 0 :icons/empty
  500.     gadid 11
  501.  
  502. xICON 600 0 :icons/empty        ; makeid
  503.     gadid 11
  504.     local word/out
  505.     SendRexx $cedport cut
  506.     lvuse CedClip.g 1
  507.     lvchange 'CLIPS:$cedClip'
  508.     word = $$lv.rec
  509.     cutvar word cut word 1 word
  510.     extract word upper word
  511.     lvclear
  512.     lvadd "#define $word\t\tMakeID(\'$word[0][1]\',\'$word[1][1]\',\'$word[2][1]\',\'$word[3][1]\')\t// "
  513.     lvsave 'CLIPS:$cedClip'
  514.     SendRexx $cedport paste
  515.  
  516.  
  517. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  518. ;    gadid 12
  519. ; ===========================================================
  520. ;    ALT2 mode
  521. ; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  522.  
  523. xICON 425 0 :icons/Compile        ; C gui
  524.     gadid 12
  525.     guiclose sc.gc
  526.     guiload :sc.gc
  527.  
  528. xICON 450 0 :icons/AGJoin        ; AmigaGuide editor
  529.     gadid 12
  530.     guiclose guideed.g
  531.     guiload :GuideEd.g
  532.  
  533. xICON 475 0 :icons/empty
  534.     gadid 12
  535.  
  536. xICON 500 0 :icons/empty
  537.     gadid 12
  538.  
  539. xICON 525 0 :icons/Dir            ; dir.gc
  540.     gadid 12
  541.     guiclose dir.gc    ; in case it's open on another screen
  542.     guiload guis:dir/dir.gc ; auto-opens..
  543.  
  544. xICON 550 0 :icons/calc            ; calculator
  545.     gadid 12
  546.     ifexists gui ~calc.gc     ; if not already loaded
  547.         ifexists file guis:tools/calc.gc
  548.             guiload guis:tools/calc.gc
  549.         else
  550.             guiload :calc.gc ; same dir ?
  551.         endif
  552.     endif
  553.     guiopen calc.gc
  554.     guiscreen calc.gc front
  555.  
  556. xICON 575 0 :icons/search        ; search gui
  557.     gadid 12
  558.     ; get current file path
  559.     gosub cedbar.gc getname
  560.     if $textpath < ' '
  561.        textpath = sys:
  562.     endif
  563.     ; get selected text into clip lv
  564.     SendRexx $cedport copy
  565.     lvuse CedClip.g 1
  566.     lvchange 'CLIPS:$cedClip'
  567.  
  568.     ; startup fsearch.gc
  569.     ifexists gui fsearch.gc    ; already open..
  570.         fsearch.gc/searchpath = $textpath
  571.         update fsearch.gc 2 $textpath
  572.         fsearch.gc/findtxt = '$$lv.rec'
  573.         update fsearch.gc 7 $fsearch.gc/findtxt
  574.         guiopen fsearch.gc
  575.         guiscreen fsearch.gc front
  576.     else
  577.         ; first look in same dir..
  578.         extract #this guipath progname
  579.         Joinfile $progname fsearch/fsearch.gc progname
  580.         ifexists file '$progname'
  581.             guiload $progname '$textpath' '$$lv.rec'
  582.         elseifexists file guis:g4c/fsearch/fsearch.gc
  583.             guiload guis:g4c/fsearch/fsearch.gc '$textpath' '$$lv.rec'
  584.         else
  585.             ezreq 'Could not locate FSearch.gc' Abort ''
  586.         endif
  587.     endif
  588.  
  589. xICON 600 0 :icons/info
  590.     gadid 12
  591.     local path/guidename ; local vars
  592.     ;  close previous guide if any
  593.     ifexists port CEDGUIDE
  594.        sendrexx CEDGUIDE QUIT
  595.     endif
  596.     extract cedbar.gc guipath path
  597.     joinfile $path CedBar.guide guidename
  598.     run 'amigaguide $guidename screen=$cedscreen port=CEDGUIDE'
  599.  
  600.  
  601. ; -----------------------------------------------------------
  602. ;     a hidden listview - used for file manipulation
  603. ; -----------------------------------------------------------
  604.  
  605. XLISTVIEW 0 0 87 110 '' lvr '' 0 MULTI
  606.     gadid 20
  607.  
  608.  
  609. ; -----------------------------------------------------------
  610. ;     routine to get current filename & path
  611. ; -----------------------------------------------------------
  612.  
  613. xroutine getname
  614.     sendrexx $cedport 'status filename'
  615.     filename = $$rexxret
  616.     extract filename path textpath
  617.  
  618.  
  619.